using UnityEngine;
using System.Collections;
using System;

namespace Flaschengeist.Processes 
{
	public class CameraZoomIn : MonoBehaviour
	{
		private bool isActive;
		
		public void Process()
		{
			isActive = true;
		}
		
		public void Update()
		{
			if (isActive) 
			{
				isActive = false;
				
				if(CameraCenterX())
				{
					if(gameObject.transform.position.z < 1.6)
					{
						gameObject.transform.position += new Vector3(0.0f, 0.0f, 0.05f * Settings.CAMERA_ZOOM_SPEED);
						isActive = true;
					}
						
					if(gameObject.transform.position.y > 1)
					{
						gameObject.transform.position += new Vector3(0.0f, -0.013f * Settings.CAMERA_ZOOM_SPEED, 0.0f);
						isActive = true;
					}
					
					if (!isActive)
						Completed();
				}
				else
					isActive = true;
			
			}		
		}
		
		public event Action Completed;
		
		private bool CameraCenterX()
		{
			bool atPosition = true;
			
			if(gameObject.transform.position.x < 9.3)
			{
				gameObject.transform.position += new Vector3(0.1f * Settings.CAMERA_ZOOM_SPEED, 0.0f, 0.0f);
				atPosition = false;
			}
			else if(gameObject.transform.position.x > 9.7)
			{
				gameObject.transform.position += new Vector3(-0.1f * Settings.CAMERA_ZOOM_SPEED, 0.0f, 0.0f);
				atPosition = false;
			}
			
			return atPosition;
		}
	}
}

